﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SF.Base.Core;
using System.Text;

namespace SF.Dict.Web.UserControls {
	public partial class ucAbcd : BaseControl {
		public string VocabularyId {
			get;
			set;
		}

		public string Initial {
			get;
			set;
		}

		protected string ABCD {
			get;
			set;
		}

		protected void Page_Load(object sender, EventArgs e) {
			if (string.IsNullOrEmpty(VocabularyId)) {
				Logger.Error("ucAbcd.ascx", "VocabularyId is null");
				return;
			}
			List<DictInitialListEntity> AbcdCount = VocabularyRules.GetInitialCount(VocabularyId);
			if (AbcdCount == null || AbcdCount.Count == 0) {
				Logger.Error("ucAbcd.ascx", "GetInitialCount is Null or =0");
				return;
			}

			string[] ABCDS = { "A", "B", "C", "D", "|", "E", "F", "G", "|", "H", "I", "J", "K", "|", "L", "M", "N", "|", "O", "P", "Q", "|", "R", "S", "T", "|", "U", "V", "W", "|", "X", "Y", "Z" };

			StringBuilder sb = new StringBuilder();

			foreach (string c in ABCDS) {
				if (c == "|") {
					sb.AppendLine("<li class=\"s\"><span>|</span></li>");
				}
				else {
					sb.AppendLine("<li><a class=\"" + (c == Initial ? "current" : "") + "\" href=\"Voc.aspx?vid=" + VocabularyRules.GetNumId(VocabularyId) + "&index=" + c + "\">" + c + "</a></li>");
				}
			}

			ABCD = sb.ToString();
		}
	}
}